//
//  StringSlicer.m
//  CardWarrior
//
//  Created by Tekka Xie on 12-4-25.
//  Copyright (c) 2012年 Tencent. All rights reserved.
//

#import "StringSlicer.h"

@implementation StringSlicer

+(NSMutableArray*)SliceStr:(NSString*)src subLen:(int)everyLen{
	__autoreleasing NSMutableArray* ret = [[NSMutableArray alloc] init] ;
	__autoreleasing NSArray* words = [src componentsSeparatedByString:@" "] ;
	int i = 0 ;
	int num = words.count ;
	while (i < num) {
		NSMutableString* str = [[NSMutableString alloc] init] ;
		NSString* sub        = (NSString*)[words objectAtIndex:i];
		while (str.length + sub.length + 1 <= everyLen && i < num) {
			[str appendString:sub];
			[str appendString:@" "] ;
			
			++i ;
			if (i < num) {
				sub        = (NSString*)[words objectAtIndex:i];
			}
		}
		
		[ret addObject:str];
	}

	return ret ;
}


@end
